﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Physis.Core.Entity {

    public class EntityAddress : CoreDateSegmentObject {

        #region Private Properties

        private Int64 entityId;


        private Core.Entity.Enumerations.AddressType addressType = Enumerations.AddressType.NotSpecified;

        private String line1;

        private String line2;

        private String city;

        private String state;

        private String zipCode;

        private String zipPlus4;

        private String postalCode;

        private String county;

        
        private Entity entity = null;

        #endregion


        #region Public Properties

        public Int64 EntityId { get { return entityId; } set { entityId = value; } }

        public Core.Entity.Enumerations.AddressType AddressType { get { return addressType; } set { addressType = value; } }

        public String AddressTypeDescription { get { return Data.Functions.EnumerationToString (addressType); } }


        public String Line1 { get { return line1; } set { line1 = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressLine); } }

        public String Line2 { get { return line2; } set { line2 = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressLine); } }

        public String City { get { return city; } set { city = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressCity); } }

        public String State { get { return state; } set { state = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressState); } }

        public String ZipCode { get { return zipCode; } set { zipCode = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressZipCode); } }

        public String ZipPlus4 { get { return zipPlus4; } set { zipPlus4 = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressZipPlus4); } }

        public String PostalCode { get { return postalCode; } set { postalCode = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressPostalCode); } }

        public String County { get { return county; } set { county = Data.Functions.SetValueMaxLength (value, Data.DataTypeConstants.AddressCounty); } }

        
        public String CityStateZipCode {

            get {

                String description = String.Empty;

                description = city + ", " + state + " " + zipCode + ((zipPlus4.Trim ().Length != 0) ? "-" + zipPlus4 : String.Empty);

                return description;

            }

        }

        public String AddressSingleLine {

            get {

                String singleLine;

                singleLine = line1 + " " + ((line2.Trim ().Length != 0) ? ", " + line2 : String.Empty) + ", " + CityStateZipCode;

                return singleLine;

            }

        }


        public Entity Entity {

            get {

                if (entity == null) { entity = Application.Core.Entity.Entity (entityId, true); }

                return entity;

            }

        }

        #endregion


        #region Constructors

        public EntityAddress (Application forApplication) : base (forApplication) {

            return;

        }

        public EntityAddress (Application forApplication, Int64 forId) : base (forApplication, forId) {

            return;

        }

        #endregion

    }

}
